<?php

include dirname( __FILE__ )."/header.php";

$lid = isset($_GET['lid']) ? intval($_GET['lid']) : 0;
$cid = isset($_GET['cid']) ? intval($_GET['cid']) : 0;
if ( empty($lid) ) {
	die("No lid!");
} elseif ( empty($cid) ) {
	die("No cid!");
}

$q = "SELECT d.lid, d.cid, d.title FROM ".$xoopsDB->prefix($mydirname."_downloads")." d, ".$xoopsDB->prefix($mydirname."_text")." t WHERE d.lid=$lid AND d.lid=t.lid AND status>0";

$result=$xoopsDB->query($q);
list($lid, $cid, $title)=$xoopsDB->fetchRow($result);

if ( empty($lid) ) {
	die("No data! Please check its cid and lid!");
}

$can_bookmark = 0;
if ( $mydownloads_can_bookmark == 0 ) {
	$can_bookmark = 0;
}
else if ( $mydownloads_can_bookmark == 1) {
	$can_bookmark = 1;
}
else if ( $mydownloads_can_bookmark == 2) {
	if ( $xoopsUser ) {
	$can_bookmark =1;
	}
	else {
	$can_bookmark =0;
	}
}
else {
	$can_bookmark = 0;
}

if ( empty($can_bookmark) ) {
	die("Not allowed now!");
}

$can_qrcode = 0;
if ( $mydownloads_can_qrcode == 0 ) {
	$can_qrcode = 0;
}
else if ( $mydownloads_can_qrcode == 1) {
	$can_qrcode = 1;
}
else if ( $mydownloads_can_qrcode == 2) {
	if ( $xoopsUser ) {
	$can_qrcode =1;
	}
	else {
	$can_qrcode =0;
	}
}
else {
	$can_qrcode = 0;
}

xoops_header(false);


$myts =& MyTextSanitizer::getInstance();

$down_title = $myts->makeTboxData4Show($title);
$down_url = XOOPSMYDOWNLOADURL."/singlefile.php?cid=".$cid."&amp;lid=".$lid;

$down_url_en = urlencode(mb_convert_encoding($down_url, "UTF-8", _CHARSET));
$down_title_en = urlencode(mb_convert_encoding($down_title, "UTF-8", _CHARSET));


function bookmark_convert_encoding($str, $to = 'SJIS', $from = _CHARSET) 
{
	if (function_exists('mb_convert_encoding')) {
		if (is_array($str)) {
			foreach ($str as $key=>$val) {
				$str[$key] = bookmark_convert_encoding($val, $to, $from);
			}
			return $str;
		} else {
			return mb_convert_encoding($str, $to, $from);
		}
	}else {
		return $str;
	}
}

function bookmark_qrcode_encoding($data="") {
$data = bookmark_convert_encoding($data);
$data = rawurlencode($data);
$data = ereg_replace("%20", "+", $data);
return $data;
}

$qrcodedata_url = bookmark_qrcode_encoding($down_url);
$siteqrcode = "<img alt='".$down_url."' title='".$down_url."'src='".XOOPS_URL."/modules/qrcode/qrcode_image.php?d=$qrcodedata_url&amp;e=M&amp;s=4&amp;v=0&amp;t=P&amp;rgb=000000' />\n";

/*
$qrcodedata_docomo_bookmark = bookmark_qrcode_encoding("MEBKM:TITLE:".$down_title.";URL:".$down_url.";;");
$bookmarkqrcode_docomo = "<img alt='docomo' title='docomo'src='".XOOPS_URL."/modules/qrcode/qrcode_image.php?d=$qrcodedata_docomo_bookmark&amp;e=M&amp;s=4&amp;v=0&amp;t=P&amp;rgb=000000' />\n";

$qrcodedata_softbank_bookmark = bookmark_qrcode_encoding("TITLE:".$down_title."\r\nURL:".$down_url."\r\n");
$bookmarkqrcode_softbank = "<img alt='softbank and au' title='softbank and au'src='".XOOPS_URL."/modules/qrcode/qrcode_image.php?d=$qrcodedata_softbank_bookmark&amp;e=M&amp;s=4&amp;v=0&amp;t=P&amp;rgb=000000' />\n";

$qrcodedata_bookmark = bookmark_qrcode_encoding("TITLE:\r\n".$down_title."\r\nURL:\r\n".$down_url."\r\n");
$bookmarkqrcode = "<img alt='title and url' title='title and url'src='".XOOPS_URL."/modules/qrcode/qrcode_image.php?d=$qrcodedata_bookmark&amp;e=M&amp;s=4&amp;v=0&amp;t=P&amp;rgb=000000' />\n";
*/


echo '
<script type="text/javascript">
<!--//
/***********************************************
* Bookmark site script-Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement("a");
	elem.setAttribute("href",url);
	elem.setAttribute("title",title);
	elem.setAttribute("rel","sidebar");
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}
//-->
</script>
</head>
<body>
<script type="text/javascript">
<!--//
var addtoMethod=0;
//-->
</script>
<script src="'.XOOPSMYDOWNLOADINCURL.'/addto-multi.js" type="text/javascript"></script>

	<table width="95%" class="outer">
            <tr><td colspan="2" align="center"><h3>'._MD_MYDOWNLOADS_BOOKMARK_SERVICE.'</h3></td></tr>
            <tr><td  class="head" align="center"><b>Download Title</b></td><td  class="even" align="center">'.$down_title.'</td></tr>
            <tr><td  class="head" align="center"><b>Download URL</b></td><td  class="even" align="center"><a href="'.$down_url.'" target="_blank">'.$down_url.'</a></td></tr>';
if ( $can_qrcode ) {
echo '<tr><td  class="head" align="center"><b>QR Code<br />(Download URL)</b></td><td  class="even" align="center">'.$siteqrcode.'</td></tr>';
}
echo '</table>
	<br /><br />
	<table width="90%">
            <tr class="foot"><td colspan="2" align="center"><b>'._MD_MYDOWNLOADS_BOOKMARK_ADDTO.'</b></td></tr>
	<tr>
	<td class="even">
<span title="Add this download to Blink"><a style="cursor:pointer;" onclick="addto(1,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Blink.gif" width="16" height="16" border="0" alt="Blink" /> Blink</a></span>
<br />
<span title="Add this download to Delicious"><a style="cursor:pointer;" onclick="addto(2,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Delicious.gif" width="16" height="16" border="0" alt="Del.icio.us" /> Del.icio.us</a></span>
<br />
<span title="Add this download to Digg"><a style="cursor:pointer;" onclick="addto(3,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Digg.gif" width="16" height="16" border="0" alt="Digg" /> Digg</a></span>
<br />
<span title="Add this download to Furl"><a style="cursor:pointer;" onclick="addto(4,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Furl.gif" width="16" height="16" border="0" alt="Furl" /> Furl</a></span>
<br />
<span title="Add this download to Blue Dot"><a style="cursor:pointer;" onclick="addto(9,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Bluedot.png" width="16" height="16" border="0" alt="Bluedot" /> Blue Dot</a></span>
<br />
<span title="Add this download to BookmarkTracker"><a style="cursor:pointer;" onclick="addto(11,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Bookmarktracker.gif" width="16" height="16" border="0" alt="Bookmarktracker" /> BookmarkTracker</a></span>
<br />
<span title="Add this download to Hatena"><a style="cursor:pointer;" onclick="addto(13,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Hatena.gif" width="16" height="16" border="0" alt="Hatena" /> Hatena</a></span>
<br />
<span title="Add this download to Magnolia"><a style="cursor:pointer;" onclick="addto(15,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Magnolia.png" width="16" height="16" border="0" alt="Magnolia" /> Magnolia</a></span>
<br />
<span title="Add this download to Nifty Clip"><a style="cursor:pointer;" onclick="addto(17,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Niftyclip.gif" width="16" height="16" border="0" alt="Nifty Clip" /> Nifty Clip</a></span>
<br />
<span title="Add this download to Pookmark"><a style="cursor:pointer;" onclick="addto(19,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Pookmark.gif" width="16" height="16" border="0" alt="Pookmark" /> Pookmark</a></span>
<br />
<span title="Add this download to Tailrank"><a style="cursor:pointer;" onclick="addto(21,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Tailrank.png" width="16" height="16" border="0" alt="Tailrank" /> Tailrank</a></span>
<br />
<span title="Add this download to Technorati"><a style="cursor:pointer;" onclick="addto(23,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Technorati.png" width="16" height="16" border="0" alt="Technorati" /> Technorati</a></span>

	</td>
	<td class="odd">
<span title="Add this download to Google"><a style="cursor:pointer;" onclick="addto(5,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Google.gif" width="16" height="16" border="0" alt="Google" /> Google</a></span>
<br />
<span title="Add this download to Simpy"><a style="cursor:pointer;" onclick="addto(6,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Simpy.gif" width="16" height="16" border="0" alt="Simpy" /> Simpy</a></span>
<br />
<span title="Add this download to Spurl"><a style="cursor:pointer;" onclick="addto(8,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Spurl.gif" width="16" height="16" border="0" alt="Spurl" /> Spurl</a></span>
<br />
<span title="Add this download to Yahoo! MyWeb"><a style="cursor:pointer;" onclick="addto(7,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Yahoo.gif" width="16" height="16" border="0" alt="Y!MyWeb" /> Y! MyWeb</a></span>
<br />
<span title="Add this download to Blogmarks"><a style="cursor:pointer;" onclick="addto(10,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Blogmarks.png" width="16" height="16" border="0" alt="Blogmarks" /> Blogmarks</a></span>
<br />
<span title="Add this download to FC2"><a style="cursor:pointer;" onclick="addto(12,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_FC2.gif" width="16" height="16" border="0" alt="FC2" /> FC2 Bookmark</a></span>
<br />
<span title="Add this download to Livedoor Clip"><a style="cursor:pointer;" onclick="addto(14,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Livedoorclip.gif" width="16" height="16" border="0" alt="Livedoor Clip" /> Livedoor Clip</a></span>
<br />
<span title="Add this download to Netscape"><a style="cursor:pointer;" onclick="addto(16,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Netscape.gif" width="16" height="16" border="0" alt="Netscape" /> Netscape</a></span>
<br />
<span title="Add this download to Newsvine"><a style="cursor:pointer;" onclick="addto(18,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Newsvine.gif" width="16" height="16" border="0" alt="Newsvine" /> Newsvine</a></span>
<br />
<span title="Add this download to Reddit"><a style="cursor:pointer;" onclick="addto(20,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Reddit.gif" width="16" height="16" border="0" alt="Reddit" /> Reddit</a></span>
<br />
<span title="Add this download to Windows Live"><a style="cursor:pointer;" onclick="addto(22,\''.$down_url_en.'\', \''.$down_title_en.'\')">
<img src="'.XOOPSMYDOWNLOADIMGURL.'/addto/AddTo_Windowslive.gif" width="16" height="16" border="0" alt="Windows Live" /> Windows Live</a></span>
<br />
<span title="Add this download to Browser Bookmark"><a style="cursor:pointer;" href="javascript:void(0);" onclick="bookmarksite(\''.$down_title.'\', \''.$down_url.'\');">
# Browser Bookmark</a></span>
	</td>
	</tr></table>
<br /><br />
';

xoops_footer();

?>